-
Notifications
You must be signed in to change notification settings - Fork 13
fix: improve performance of ApplyPowerTableDiffs in ImportSnapshotToDatastore #1047
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: improve performance of ApplyPowerTableDiffs in ImportSnapshotToDatastore #1047
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1047 +/- ##
==========================================
- Coverage 64.77% 64.46% -0.31%
==========================================
Files 81 81
Lines 9896 9942 +46
==========================================
- Hits 6410 6409 -1
- Misses 2961 2999 +38
- Partials 525 534 +9
🚀 New features to boost your workflow:
|
5fbd9b1
to
af0db51
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR optimizes the performance of applying power table diffs during F3 snapshot import by introducing a new map-based approach that avoids expensive sorting operations on each iteration. The optimization shows a ~99% performance improvement when importing mainnet F3 snapshots.
- Introduced
ApplyPowerTableDiffsToMap
function to work with power table maps instead of sorted arrays - Added comprehensive validation for instance numbers, latest instance bounds, and power table CID verification
- Refactored
importSnapshotToDatastoreWithTestingPowerTableFrequency
to use the new map-based approach and include additional safety checks
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
File | Description |
---|---|
certstore/snapshot.go | Refactored snapshot import logic to use map-based power table operations and added validation checks |
certs/certs.go | Added new map-based power table diff functions and helper functions for array-map conversion |
SGTM apart from the two issues highlighted by Copilot |
The
sort
operation inApplyPowerTableDiffs
turns out to be expensive.This PR introduces another
func ApplyPowerTableDiffsToMap(powerTableMap map[gpbft.ActorID]gpbft.PowerEntry, diffs ...PowerTableDiff) (map[gpbft.ActorID]gpbft.PowerEntry, error)
to avoid sorting.It also adds more validations against first instance, latest instance and powertable cid.
Perf stats of importing a mainnet F3 snapshot on my laptop show ~99% perf gain